
$(function(){
	var re = /item-(\d+)/;
	$('td.si > img').each(function(i,e){
		var o = $(e);
		var r = re.exec(o.attr('src'));
		var tmp = r[1];
		o.before("<div>" + tmp + "</div>");
		o.click(function(){
			on_img_click($(this),tmp);
		});
		o.hover(
			function(){
				on_img_hover($(this),tmp);
			},
			function(){
				on_img_out($(this),tmp);
			}
			);
	});
	$("#iout").val("");
});
function on_img_click(i,n){
	var o = i.parent();
	var u = $("#iout")
	var val = u.val();
	if(o.hasClass("sel")){
		o.removeClass("sel");
		var re_val = new RegExp(" " + n + ",\\d+");
		u.val(val.replace(re_val, ""))
	}else{
		o.addClass("sel");
		u.val(val + " " + n + ",0");
	}
}
var tid = -1;
function on_img_hover(i,n){
	$("#pre").html("<img src='../" + shop_path_info + "/item-" + n + ".jpg'>");
	if(tid != -1){
		clearTimeout(tid)
		tid = -1
	}
}
function on_img_out(i,n){
	if(tid != -1){
		clearTimeout(tid)
		tid = -1
	}
	tid = setTimeout(function(){
		$("#pre").html("<br>");
	},500);
}